package io.sage.modules.goods.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.sage.annotation.Login;
import io.sage.annotation.LoginUser;
import io.sage.common.utils.R;
import io.sage.entity.UserEntity;
import io.sage.modules.goods.entity.BGoodsRecord;
import io.sage.modules.goods.service.BGoodsRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 物品检查记录表(BGoodsRecord)表控制层
 *
 * @author zxh
 * @since 2019-08-05 16:23:40
 */
@RestController
@RequestMapping("sage/goodsRecord")
public class BGoodsRecordController {
    /**
     * 服务对象
     */
    @Resource
    private BGoodsRecordService bGoodsRecordService;

    /**
     * 通过用户id查询多条数据
     *
     * @param jsonObject
     * @return 多条数据
     */
    @PostMapping("selectAll")
    @Login
    @ApiOperation("已办查询")
    public R selectAll(@ApiIgnore @LoginUser UserEntity user , @RequestBody JSONObject jsonObject) {
        Integer pageSize = 10;
        if (jsonObject.getInteger("limit") != null) {
            pageSize = jsonObject.getInteger("limit");
        }
        Integer pageNum = 0;
        if (jsonObject.getInteger("page") != null) {
            pageNum = jsonObject.getInteger("page");

        }
        BGoodsRecord bGoodsRecord=new BGoodsRecord();
        bGoodsRecord.setUserId(user.getUserId());
        bGoodsRecord.setIsDel(0);
        PageHelper.startPage(pageNum, pageSize);// 设置分页的起始码以及页面大小
        List<BGoodsRecord> selectGoodsList = bGoodsRecordService.queryAll(bGoodsRecord);

        PageInfo<BGoodsRecord> pageInfo = new PageInfo<BGoodsRecord>(selectGoodsList);// 传入list就可以了

        return R.ok().put("list", pageInfo);
    }
    /**
     * 通过id查询单条数据
     *
     * @param id
     * @return 单条数据
     */
    @GetMapping("selectOne/{id}")
    @Login
    @ApiOperation("已办查询 通过id")
    public R selectOne(@PathVariable Integer id) {

        return R.ok().put("record", this.bGoodsRecordService.queryById(id));
    }

}